{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{% load mytags %}

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{{ area_name }}-白名单管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a>
                            </li>
                            <li><a href="#">Config option 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-5 m-b-xs">
                        {% for num in inc_area_info %}
                            <a  class="btn btn-primary btn-write dim" href="?area={{num}}"> {{num}}</a>
                        {% endfor %}
                       </div>

                        <div class="pull-right">
                          <a onclick="fnClickAddRow();" href="javascript:void(0);" class="btn btn-primary dim">增加白名单</a>
                        </div>
                    </div>
                    <div class="table-responsive">
                      {% if data_log %}
                          <div class="alert alert-success text-center">{{ data_log }}</div>
                      {% endif %}

                      {% if error_log %}
                           <div class="alert alert-danger text-center">{{ error_log }}</div>
                      {% endif %}
                        <form id="contents_form" name="contents_form" >
                            <table class="table table-striped table-bordered table-hover" id="editable" name="editable">
                                <thead>
                                    <tr>
                                        <th class="text-center"><input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')"></th>
                                        <th class="text-center">地区</th>
                                        <th class="text-center">白名单IP</th>
                                        <th class="text-center">状态</th>
                                        <th class="text-center">备注</th>
                                    </tr>
                                </thead>
                                <tbody>
                                  {% for num in menu %}
                                    <tr class="text-center">
                                        <td data-editable='false' name="white_name" value={{num.ip}}><input type="checkbox" data-toggle="checkbox" name="subcheck" value='{{num.ip}}'></td>
                                        <td data-editable='false' name="area_name">{{num.area_name}}</td>
                                        <td data-editable='false' name="ip">{{num.ip}}</td>
                                        <td name="state">{{num.state}}</td>
                                        <td name="commit">{{num.commit}}</td>
                                    </tr>
                                  {% endfor %}
                                </tbody>
                            </table>
                        </form>
                    </div>
                      <button type="submit" class="btn btn-danger btn-sm dim"  form="contents_form" formmethod="POST" formaction="/inc/white_list_edit/?area={{area_name}}&action=del">删除</button>
                      <button type="button" id="alter_button" class="btn btn-warning btn-sm dim"  onclick="alter('contents_form')" >修改</button>

                    <div>
                    <a  class="btn btn-primary btn-write dim" href="/inc/white_list_print/?area={{area_name}}"> 生成白名单文件</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
  function del_server(){
        var opendata=new Array();
        var show=document.getElementsByName('server_group');

        for(var i=0;i<show.length;i++){
            if(show[i].checked==true){
            opendata[i]=show[i].value+'<br>';
        }
    }
  for(var i=0;i<opendata.length;i++){
                if(opendata[i] == "" || typeof(opendata[i]) == "undefined")
                {
                        opendata.splice(i,1);
                        i = i-1;
                }
        }
        document.getElementById("open_list").innerHTML=opendata;
}
</script>


<script type="text/javascript">

    $(document).ready(function(){
        $('#editable').editableTableWidget({editor: $('<textarea>')});
    });


    function alter(form) {
        selectData = GetTableDataBox();
        console.log(selectData[0])
        if (selectData[1] != 0) {
            $.ajax({
                type: "get",
                url: "/inc/white_list_edit/?area={{area_name}}&action=edit",
                data: {"editable": selectData[0], "len_table": selectData[1]},
                success: function (data) {
                    alert("修改成功");
                    window.open("/inc/white_list/?area={{area_name}}", "_self");
                error: window.open("/inc/white_list/?area={{area_name}}", "_self");
                }
            });
        }
    }

    function fnClickAddRow(){
        var tr="<tr class='text-center'>\
                  <td data-editable='false' name='white_name' value='new'><input type='checkbox' name='check'/></td>\
                  <td name='area_name'>{{area_name}}</td>\
                  <td name='ip'>请修改IP</td>\
                  <td name='state'>true</td>\
                  <td name='commit'>请修改备注</td>\
                </tr>";
　  　　 $("#editable").append(tr);　　
        $('#editable').editableTableWidget({editor: $('<textarea>')});
    }

    function platClickAddRow(){
        var tr="<tr class='text-center'>\
                 <td data-editable='false' name='platform' value='{{platform}}'><input type='checkbox' name='check' value='{{num.platform}}'/></td>\
                 <td data-editable='false' name='area_name'>{{area_name}}</td>\
                 <td name='platform'>输入平台名</td>\
                 <td name='dirname'>'输入推送目录'</td>\
                </tr>";
        $("#editable_plat").append(tr);　　
        $('#editable_plat').editableTableWidget({editor: $('<textarea>')});
    }
</script>

{% endblock %}